﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using WiTeach.ClassManagement.Model;
using WiTeach.Tools;

namespace WiTeach.ClassManagement.DAL
{
    /// <summary>
    /// 课时对应文件相关数据模型处理方法
    /// </summary>
    public static class ClassHourDAL
    {
        private static string tableName = "ta_lesson";

        public static List<ClassHour> getClassListByID(int Lesson_ID ,int ClassHour_ID)
        {
            List<ClassHour> classList = new List<ClassHour>();
            string sql = "select * from " + tableName + " where course_id = " + Lesson_ID + " AND id = "+ClassHour_ID;
            DataTable classTable = SqlHelper.ExecuteDataTable(sql);
            return classToList(classTable);
        }

        public static List<ClassHour> classToList(DataTable dataTable)
        {
            List<ClassHour> classList = new List<ClassHour>();
            FileHelper fp = new FileHelper();
            if (dataTable == null)
                return null;
            foreach (DataRow dt in dataTable.Rows)
            {
                ClassHour classHour = new ClassHour();
                classHour.ID = (int)dt["id"];
                classHour.Lesson_ID = (int)dt["course_id"];
                classHour.ClassHour_ID = (int)dt["id"];
                classHour.PDFName = fp.GetExecutionDirectoryFileFullPath("",dt["pdf"].ToString());
                classHour.PPTName =  fp.GetExecutionDirectoryFileFullPath("",dt["ppt"].ToString());
                classHour.VideoName = fp.GetExecutionDirectoryFileFullPath("",dt["video"].ToString());
                classHour.Physical_Map_Url = fp.GetExecutionDirectoryFileFullPath("", dt["real"].ToString());
                classHour.Principle_Diagram_Url = fp.GetExecutionDirectoryFileFullPath("", dt["schematic"].ToString());
                classHour.Class_Job_Url = fp.GetExecutionDirectoryFileFullPath("", dt["exercise"].ToString());
                classList.Add(classHour);
            }
            return classList;
        }
    }
}
